<?php
/**
 *库存结算表
 */
declare(strict_types=1);

namespace Modules\Inventory\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Modules\Base\Models\Material;
use Modules\Warehouse\Models\Stash;
use Modules\Warehouse\Models\Storagelocation;
use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $org_code
 * @property $location
 * @property $material_no
 * @property $qty
 * @property $assign_qty
 * @property $lock_qty
 * @property $lot_num
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class InventorySettlement extends Model
{

    protected $table = 'inventory_settlement';

    protected $fillable = [ 'id', 'org_code','cargo_code','supplier_code','wms_code', 'location', 'material_no','unit', 'qty', 'assign_qty', 'lock_qty', 'lot_num', 'creator_id', 'created_at', 'updated_at', 'deleted_at'];

    /**
     * @var array
     */
    protected array $fields = ['id','org_code','cargo_code','supplier_code','wms_code','location','material_no','unit','qty','assign_qty','lock_qty','lot_num','created_at'];

    /**
     * @var array
     */
    protected array $form = ['id','org_code','cargo_code','supplier_code','wms_code','location','material_no','unit','qty','assign_qty','lock_qty','lot_num','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'org_code'      => '=',
        'cargo_code'    => '=',
        'supplier_code' => '=',
        'wms_code'      => '=',
        'location'      => '=',
        'material_no'   => 'like',
        'lot_num'       => '=',
    ];

    public function getFields(){
        return $this->fields;
    }

    /**
     * 返回产品信息
     * @return HasMany
     */
    public function material()
    {
        return $this->hasOne(Material::class,'fnumber','material_no');
    }

    /**
     * 关联库位信息
     * @return mixed
     */
    public function locations(){
        return $this->hasOne(Storagelocation::class,'warehousecode','location');
    }

    /**
     * 关联仓库信息
     * @return mixed
     */
    public function wms(){
        return $this->hasOne(Stash::class,'fnumber','wms_code');
    }

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

}
